import Cookies from 'js-cookie'

const TokenKey = 'hrsaas-ihrm-token'// 设定一个独一无二的key
const TimeKey = 'hrsaas-ihrm-time'
const loginKey = 'hrsaas-ihrm-login'

export function getToken() {
  return Cookies.get(TokenKey)
}

export function setToken(token) {
  return Cookies.set(TokenKey, token)
}

export function removeToken() {
  return Cookies.remove(TokenKey)
}

export const getTime = () => Cookies.get(TimeKey)

export const setTime = time => Cookies.set(TimeKey, time)

export const removeTime = () => Cookies.remove(TimeKey)

export const getLoginInfo = () => {
  if (Cookies.get(loginKey)) {
    return JSON.parse(Cookies.get(loginKey))
  } else {
    return null
  }
}

export const setLoginInfo = loginInfo => Cookies.set(loginKey, JSON.stringify(loginInfo))

export const removeLoginInfo = () => Cookies.remove(loginKey)
